from django.contrib.auth.models import AbstractUser
from django.db import models

# Create your models here.

class User(AbstractUser):
    gender_choices = {
        (0, "男"),
        (1, "女"),
    }

    mobile = models.CharField(max_length=11, unique=True, null=True, verbose_name="电话号码")
    avatar = models.ImageField(upload_to="avatar/", default="avatar/default.png", verbose_name="用户头像")
    gender = models.SmallIntegerField(choices=gender_choices, null=True, verbose_name="用户性别")
    age = models.SmallIntegerField(null=True, verbose_name="用户年龄")
    snow_id = models.CharField(max_length=200, null=True, verbose_name="雪花算法的用户id")

    class Meta:
        db_table = 'my_user'
        verbose_name_plural = "用户"

# 三方登录表
class OAuthUser(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户")
    uid = models.CharField(max_length=64, unique=True, verbose_name="第三方id")
    token = models.CharField(max_length=64, verbose_name="第三方token")
    type = models.SmallIntegerField(choices={(0, "微信"), (1, "钉钉"), (2, "微博")}, verbose_name="授权类型")

    class Meta:
        db_table = 'my_oauth_user'
        verbose_name_plural = "第三方登录用户"

# 用户实名表
class UserAuth(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户")
    idcard_url = models.CharField(max_length=200, verbose_name="身份证照片")
    name = models.CharField(max_length=32, verbose_name="姓名")
    idcard = models.CharField(max_length=18, unique=True, verbose_name="身份证号")

    class Meta:
        db_table = 'my_user_auth'
        verbose_name_plural = "用户实名认证"

    def __str__(self):
        return self.name
